<?php

/**
 * undocumented class
 *
 * @package default
 * @author Marc
 **/
class uvmcSolrRequestParameters
{
  protected $_parameters;
  
  /**
   * @param array $parameters
   */
  public function __construct()
  {
    $this->configure();
  }
  
  /**
   * @param array $parameters
   */
  public function configure()
  {
  }
  
  /**
   * @return array Parameters
   */
  public function getParameterHolder()
  {
    return $this->_parameters;
  }
  
  public function setQueryType($query_type)
  {
    $this->setParameter('qt', $query_type);
  }
  
  /**
   *
   * @param $name string
   * @param $value mixed
   */
  public function setParameter($name, $value)
  {
    $this->_parameters[$name] = $value;
  }
  
  /**
   *
   * @param $name string
   * @return mixed|null 
   */
  public function getParameter($name)
  {
    if (!isset($this->_parameters[$name]))
    {
      return null;
    }
    
    return $this->_parameters[$name];
  }
  
  /**
   * Enable highlighting
   * @return $this
   */
  public function highlightEnable()
  {
    $this->setParameter('hl', 'on');
    return $this;
  }
  
  /**
   * Disable highlighting
   * @return $this
   */
  public function hightlightDisable()
  {
    $this->setParameter('hl', false);
    return $this;
  }
  
  /**
   * Enable Phrase Highlighter
   * @return $this
   */
  public function highlightEnablePhraseHiglighter()
  {
    $this->setParameter('hl.usePhraseHighlighter', 'on');
    return $this;
  }

  /**
   * Disable Phrase Highlighter
   * @return $this
   */  
  public function highlightDisablePhraseHiglighter()
  {
    $this->setParameter('hl.usePhraseHighlighter', false);
    return $this;
  }

  /**
   * Set fields to be highlighted
   * @return $this
   */  
  public function highlightSetFields($fields)
  {
    $this->setParameter('hl.fl', $fields);
    return $this;
  }
  
  /**
   * Get highlighted fields
   * @return $this
   */
  public function highlightGetFields()
  {
    $this->getParameter('hl.fl');
    return $this;
  }
  
  /**
   * Enable "requireFieldMatch"
   * @return $this
   */
  public function highlightEnableRequireFieldMatch()
  {
    $this->setParameter('hl.requireFieldMatch', 'on');
    return $this;
  }
  
  /**
   * Disable "requireFieldMatch"
   * @return $this
   */
  public function highlightDisableRequireFieldMatch()
  {
    $this->setParameter('hl.requireFieldMatch', false);
    return $this;
  }
  
  /**
   * Enable "MultiTerm"
   * @return $this
   */
  public function highlightEnableMultiTerm()
  {
    $this->highlightEnablePhraseHiglighter();
    $this->setParameter('hl.highlightMultiTerm', 'on');
    return $this;
  }
  
  /**
   * Disable "MultiTerm"
   * @return $this
   */
  public function highlightDisableMultiTerm()
  {
    $this->setParameter('hl.highlightMultiTerm', false);
    return $this;
  }
  
  /**
   * Set max snippets per fields
   * @return $this
   */
  public function highlightSetMaxSnippetsPerFields($number)
  {
    $this->setParameter('hl.Snippets', $number);
    return $this;
  }
  
  /**
   * Get max snippets per fields
   * @return integer
   */
  public function highlightGetMaxSnippetsPerFields()
  {
    return $this->getParameter('hl.Snippets');
  }
  
  public function highlightSetFragmentSize($size)
  {
    $this->setParameter('hl.fragsize', $size);
    return $this;
  }
  
  public function highlightGetFragmentSize()
  {
    $this->getParameter('hl.fragsize');
    return $this;
  }
  
  public function highlightEnableMergeContiguous()
  {
    $this->setParameter('hl.mergeContiguous', 'on');
    return $this;
  }
  
  public function highlightDisableMergeContiguous()
  {
    $this->setParameter('hl.mergeContiguous', false);
    return $this;
  }
  
  public function highlightSetMaxAnalyzedChars($number)
  {
    $this->setParameter('hl.maxAnalyzedChars', $number);
    return $this;
  }
  
  public function highlightDisableMaxAnalyzedChars()
  {
    $this->setParameter('hl.maxAnalyzedChars', -1);
    return $this;
  }
  
  public function highlightSetAlternateField($field)
  {
    $this->setParameter('hl.alternateField', $field);
    return $this;
  }
  
  public function highlightSetAlternateFieldMaxLength($length)
  {
    $this->setParameter('hl.maxAlternateFieldLength', $length);
    return $this;
  }
  
  public function highlightGetAlternateFieldMaxLength($length)
  {
    return $this->setParameter('hl.maxAlternateFieldLength', $length);
  }
  
  public function highlightSetFormatter($formatter)
  {
    $this->setParameter('hl.formatter', $length);
    return $this;
  }
  
  public function highlightGetFragmenter($fragmenter)
  {
    return $this->getParameter('hl.fragmenter');
  }
  
  public function facetEnable()
  {
    $this->setParameter('facet', 'on');
    return $this; 
  }
  
  public function facetAddField($field)
  {
    if (!is_array($field))
    {
      $field = array($field);
    }
    if ($this->getParameter('facet.field') == null)
    {
      $this->setParameter('facet.field', $field);
    }
    else
    {
      $this->setParameter('facet.field', array_merge($this->getParameter('facet.field'), $field));
    }
    
    return $this;
  }
}